

package org.koyabr.webx.demo.danmaku.web.post.module.screen.detail;

import javax.servlet.http.HttpServletRequest;

import com.alibaba.citrus.turbine.dataresolver.Param;
import com.alibaba.citrus.turbine.Context;

import org.koyabr.webx.demo.danmaku.biz.PostManager;
import org.koyabr.webx.demo.danmaku.dal.dataobjs.Post;
import org.koyabr.webx.demo.danmaku.dal.dataobjs.Danmaku;
import org.springframework.beans.factory.annotation.Autowired;

public class DanmakuDst {
    @Autowired
    private PostManager postManager;
    
    @Autowired
    private HttpServletRequest request;

    public void execute(@Param("id") String postId  ,Context context) throws Exception {
        
        Post post = postManager.getPostById(postId);
        if(post == null)
        	return;
        
        Danmaku danmaku = new Danmaku(post);
        danmaku.setText(request.getParameter("message"));
        danmaku.setMode(Integer.parseInt(request.getParameter("mode")));
        danmaku.setTime(Integer.parseInt(request.getParameter("stime")));
        danmaku.setColor(Integer.parseInt(request.getParameter("color")));
        danmaku.setSize(Integer.parseInt(request.getParameter("size")));
        
        postManager.addDanmaku(danmaku);
    }
}
